package com.chenfan.process.service.impl;

import java.util.List;

import org.springframework.stereotype.Service;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.chenfan.process.common.constants.CommonFieldConstants;
import com.chenfan.process.entity.po.ProcessFormNodeRelation;
import com.chenfan.process.enums.BooleanEnum;
import com.chenfan.process.repository.ProcessFormNodeRelationRepository;
import com.chenfan.process.service.ProcessFormNodeRelationService;

/**
 * @author liuming
 * @date 2021/11/24
 */
@Service
public class ProcessFormNodeRelationServiceImpl extends
    ServiceImpl<ProcessFormNodeRelationRepository, ProcessFormNodeRelation> implements ProcessFormNodeRelationService {

    @Override
    public List<ProcessFormNodeRelation> listNodeAttributes(Long approvalTemplateId, List<Long> nextProcessId,
        Long version) {
        QueryWrapper<ProcessFormNodeRelation> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq(ProcessFormNodeRelation.Constants.APPROVAL_TEMPLATE_ID, approvalTemplateId);
        queryWrapper.in(ProcessFormNodeRelation.Constants.PROCESS_ID, nextProcessId);
        queryWrapper.eq(CommonFieldConstants.VERSION, version);
        return this.list(queryWrapper);
    }

    @Override
    public List<ProcessFormNodeRelation> listAttributes(Long approvalTemplateId, Long version) {
        QueryWrapper<ProcessFormNodeRelation> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq(ProcessFormNodeRelation.Constants.APPROVAL_TEMPLATE_ID, approvalTemplateId);
        queryWrapper.eq(CommonFieldConstants.VERSION, version);
        return this.list(queryWrapper);
    }

    @Override
    public List<ProcessFormNodeRelation> listRequiredNodeAttributes(Long approvalTemplateId, List<Long> nextProcessId,
        Long version) {
        QueryWrapper<ProcessFormNodeRelation> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq(ProcessFormNodeRelation.Constants.APPROVAL_TEMPLATE_ID, approvalTemplateId);
        queryWrapper.in(ProcessFormNodeRelation.Constants.PROCESS_ID, nextProcessId);
        queryWrapper.in(ProcessFormNodeRelation.Constants.REQUIRED, BooleanEnum.Y.getCode());
        queryWrapper.eq(CommonFieldConstants.VERSION, version);
        return this.list(queryWrapper);
    }
}
